package py.com.alfa.escriba.persistence.mybatis;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

public class DBBooleanTypeHandler implements TypeHandler<Boolean> {

	@Override
	public void setParameter(PreparedStatement ps, int i, Boolean parameter, JdbcType jdbcType) throws SQLException {
		ps.setInt(i, parameter ? 1 : 0);
	}

	@Override
	public Boolean getResult(ResultSet rs, String columnName) throws SQLException {
		return rs.getInt(columnName) == 1 ? true : false;
	}

	@Override
	public Boolean getResult(CallableStatement cs, int columnIndex) throws SQLException {
		return cs.getInt(columnIndex) == 1 ? true : false;
	}

	@Override
	public Boolean getResult(ResultSet rs, int columnIndex) throws SQLException {
		return rs.getInt(columnIndex) == 1 ? true : false;
	}

}
